package m202311.d21;

/**
 * @author haocongshun
 * @date 2023/11/21 19:27:51
 */

/**
 * 125. 验证回文串
 */
public class Q125 {

    public static void main(String[] args) {
        boolean palindrome = new Q125().isPalindrome("0P");
        System.out.println(palindrome);
    }

    public boolean isPalindrome(String s) {
        int pl = 0;
        int pr = s.length() - 1;
        while (pr > pl) {
            char left = s.charAt(pl);
            char right = s.charAt(pr);
            if (!Character.isLetterOrDigit(left)) {
                pl++;
                continue;
            }
            if (!Character.isLetterOrDigit(right)) {
                pr--;
                continue;
            }
            if (Character.toLowerCase(left) == Character.toLowerCase(right)) {
                pl++;
                pr--;
            } else {
                return false;
            }
        }
        return true;
    }
}
